package cn.apptec.test.ssm.controller;

import cn.apptec.test.ssm.model.employees.Employees;
import cn.apptec.test.ssm.model.local.User;
import cn.apptec.test.ssm.service.UserService;
import cn.apptec.test.ssm.utils.DataSourceContextHolder;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private UserService userService;



    @RequestMapping("/helloworld")
    @ResponseBody
    public String helloWorld() {
        DataSourceContextHolder.setDbType("localDataSource");
        User user = userService.getUserById(1);
        return JSON.toJSONString(user);

    }

    @RequestMapping("/emp")
    @ResponseBody
    public String emp() {
        Employees test = userService.test();
        return JSON.toJSONString(test);
    }

    @RequestMapping("/emp2")
    @ResponseBody
    public String emp2() {
        User userById = userService.getUserById(1);
        return JSON.toJSONString(userById);
    }
}